package hys.wssoc.modules.info.controller;

import hys.wssoc.common.utils.PageUtils;
import hys.wssoc.common.utils.R;
import hys.wssoc.modules.info.entity.CityEntity;
import hys.wssoc.modules.info.service.CityService;
import hys.wssoc.modules.info.vo.CitySummaryVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * @author hys
 * @email 2439206957@qq.com
 * @date 2024-03-08 11:46:51
 */
@RestController
@RequestMapping("info/city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cityService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{cityId}")
    public R info(@PathVariable("cityId") Integer cityId){
		CityEntity city = cityService.getById(cityId);

        return R.ok().put("city", city);
    }

    @RequestMapping("/summary/list")
    public R summaryList(@RequestParam(name = "provinceName")String provinceName){
        List<CitySummaryVo> summaryList = cityService.selectList(provinceName);
        return R.ok().put("summaryList", summaryList);
    }

    @RequestMapping("/detail")
    public R detail(@RequestParam("cityName")String cityName){
        CitySummaryVo cityDetail = cityService.detail(cityName);

        return R.ok().put("cityDetail", cityDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("info:city:save")
    public R save(@RequestBody CityEntity city){
		cityService.save(city);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("info:city:update")
    public R update(@RequestBody CityEntity city){
		cityService.updateById(city);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("info:city:delete")
    public R delete(@RequestBody Integer[] cityIds){
		cityService.removeByIds(Arrays.asList(cityIds));

        return R.ok();
    }

}
